﻿#region File Description
//-----------------------------------------------------------------------------
// HelpScreen.cs
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
#endregion
namespace ManagerGame.Screens
{
    class HelpScreen : MenuScreen
    {

        Texture2D gradientTexture;

        string message =
@"Welcome to Manager Game. In this game, 
you take the role of an aspiring entrepreneur with 
a small amount of money to invest. 
START: In the start 
menu you can alter the number of turns played and initial 
amount of money. Saving and loading the game are disabled at the moment. 
MAIN GAME SCREEN: In the main game screen you guide your 
sickly green entrepreneur around the city. Go to pub to 
purchase pubs and manage your pubs. Currently you can only 
manage the pub you last bought, so be careful out there. 
You can end the turn by going to your office or by pressing T. 
Pressing H brings up this help menu. You can move the little 
fellow with arrow keys. 
PUB MANAGEMENT SCREEN: Here you can 
either buy a new pub or manage the last pub you bought and alter the 
number of workers hired or the amount of salary you pay to one worker.
MOVING AROUND: Move the little green man around with arrow keys.
In menu screens, move with up and down arrows, accept choices with
space or enter. Return to game with space.
LIMITED ALPHA VERSION: You can only manage pubs and manage pubs
in descending order from last to first.";

        MenuEntry menuEntry;
        SpriteFont font;
         /// <summary>
        /// Constructor.
        /// </summary>
        public HelpScreen()
            : base("Info")
        {

            // Create our menu entries.
            MenuEntry resumeGameMenuEntry = new MenuEntry("");

            menuEntry = resumeGameMenuEntry;
            // Hook up menu event handlers.
            resumeGameMenuEntry.Selected += OnCancel;

            // Add an entry to the menu.
            MenuEntries.Add(resumeGameMenuEntry);
        }

        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;
            font = content.Load<SpriteFont>("HelpScreenFont");
            gradientTexture = content.Load<Texture2D>("gradient");
        }

        /// <summary>
        /// Helper overload makes it easy to use OnCancel as a MenuEntry event handler.
        /// </summary>
        protected new void OnCancel(object sender, PlayerIndexEventArgs e)
        {
            OnCancel(e.PlayerIndex);
        }

        /// <summary>
        /// Allows the screen the chance to position the menu entries. By default
        /// all menu entries are lined up in a vertical list, centered on the screen.
        /// </summary>
        protected new virtual void UpdateMenuEntryLocations()
        {
            // Make the menu slide into place during transitions, using a
            // power curve to make things look more interesting (this makes
            // the movement slow down as it nears the end).
            float transitionOffset = (float)Math.Pow(TransitionPosition, 2);

            // start at Y = 175; each X value is generated per entry
            Vector2 position = new Vector2(0f, 150f);

            // each entry is to be centered horizontally
            position.X = ScreenManager.GraphicsDevice.Viewport.Width / 2 - menuEntry.GetWidth(this) / 2;

            if (ScreenState == ScreenState.TransitionOn)
                position.X -= transitionOffset * 256;
            else
                position.X += transitionOffset * 512;

            // set the entry's position
            menuEntry.Position = position;

            // move down for the next entry the size of this entry
            position.Y += menuEntry.GetHeight(this);
            
        }


        /// <summary>
        /// Draws the message box.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            UpdateMenuEntryLocations();
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            

            // Darken down any other screens that were drawn beneath the popup.
            ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);

            // Center the message text in the viewport.
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
            Vector2 textSize = font.MeasureString(message);
            Vector2 textPosition = (viewportSize - textSize) / 2;

            // The background includes a border somewhat larger than the text itself.
            const int hPad = 32;
            const int vPad = 16;

            

            Rectangle backgroundRectangle = new Rectangle((int)textPosition.X - hPad,
                                                          (int)textPosition.Y - vPad,
                                                          (int)textSize.X + hPad * 2,
                                                          (int)textSize.Y + vPad * 2);

            // Fade the popup alpha during transitions.
            Color color = Color.White * TransitionAlpha;

            spriteBatch.Begin();

            // Draw the background rectangle.
            spriteBatch.Draw(gradientTexture, backgroundRectangle, color);
            menuEntry.Draw(this, true, gameTime);
            // Draw the message box text.
            spriteBatch.DrawString(font, message, textPosition, color);

            spriteBatch.End();
        }
    }
}
